{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "cf9d4d34-b3db-4df1-a5e0-908edfe3a522",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "length:  28522\n",
      "0x9316\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from fontTools import ttLib\n",
    "from fontTools.pens.svgPathPen import SVGPathPen\n",
    "from fontTools.pens.transformPen import TransformPen\n",
    "import svgwrite\n",
    "\n",
    "# cmap有28522个, glyf有28562个\n",
    "font = ttLib.TTFont('simkai.ttf')\n",
    "# cmap有667个, glyf有690个\n",
    "# font = ttLib.TTFont('segoepr.ttf')\n",
    "print(len(font['cmap'].tables))\n",
    "m = font['cmap'].tables[0].cmap\n",
    "# print(m.items()) # k是该字的整型uni编码 v是该字的uni编码 表示为uni+4位十六进制数字\n",
    "print('length: ',len(m))\n",
    "target = 'uni9316'\n",
    "for k,v in m.items():\n",
    "    if v == target:\n",
    "        print('%#x'%k) # 打印16进制数字\n",
    "        break\n",
    "target in m.values() # 这里可以判断是否存在该字\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "d0f8a1f9-f240-4e32-b079-6e87d7ec2734",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['__abstractmethods__',\n",
       " '__class__',\n",
       " '__class_getitem__',\n",
       " '__contains__',\n",
       " '__delattr__',\n",
       " '__dict__',\n",
       " '__dir__',\n",
       " '__doc__',\n",
       " '__eq__',\n",
       " '__format__',\n",
       " '__ge__',\n",
       " '__getattribute__',\n",
       " '__getitem__',\n",
       " '__getstate__',\n",
       " '__gt__',\n",
       " '__hash__',\n",
       " '__init__',\n",
       " '__init_subclass__',\n",
       " '__iter__',\n",
       " '__le__',\n",
       " '__len__',\n",
       " '__lt__',\n",
       " '__module__',\n",
       " '__ne__',\n",
       " '__new__',\n",
       " '__reduce__',\n",
       " '__reduce_ex__',\n",
       " '__repr__',\n",
       " '__reversed__',\n",
       " '__setattr__',\n",
       " '__sizeof__',\n",
       " '__slots__',\n",
       " '__str__',\n",
       " '__subclasshook__',\n",
       " '__weakref__',\n",
       " '_abc_impl',\n",
       " 'defaultLocationNormalized',\n",
       " 'depth',\n",
       " 'font',\n",
       " 'get',\n",
       " 'glyfTable',\n",
       " 'glyphsMapping',\n",
       " 'gvarTable',\n",
       " 'hMetrics',\n",
       " 'has_key',\n",
       " 'hvarTable',\n",
       " 'items',\n",
       " 'keys',\n",
       " 'location',\n",
       " 'locationStack',\n",
       " 'originalLocation',\n",
       " 'pushDepth',\n",
       " 'pushLocation',\n",
       " 'rawLocation',\n",
       " 'rawLocationStack',\n",
       " 'recalcBounds',\n",
       " 'vMetrics',\n",
       " 'values']"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取字形数据\n",
    "glyf_table = font[\"glyf\"]\n",
    "glyph_set = font.getGlyphSet()\n",
    "dir(glyph_set)\n",
    "# print(len(glyf_table.keys()))\n",
    "# print(glyf_table.keys())\n",
    "# c = 'uni3114'\n",
    "# glyf_table.getGlyphID(c)\n",
    "# glyf_table.getPhantomPoints(c,font)\n",
    "# for k,v in glyph_set.items():\n",
    "#     print(k,v)\n",
    "# one_set = glyph_set['percent'].glyphSet\n",
    "# dir(one_set['a'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac7bb0e9-f186-4899-990d-fab0f51012e8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:ai]",
   "language": "python",
   "name": "conda-env-ai-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
